package com.botao.tip.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.botao.tip.dao.ProductMapper;
import com.botao.tip.dao.PurchaseMapper;
import com.botao.tip.entity.Product;
import com.botao.tip.entity.Purchase;
import com.botao.tip.service.ProductService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @author : vip865047755@126.com
 * @version :JDK1.8
 * @date : 2020-12-03 16:45
 * @File : ProductServiceImpl.java
 * @software: IntelliJ IDEA
 */
@Service
@Transactional(rollbackFor = Exception.class)
public class ProductServiceImpl extends ServiceImpl<ProductMapper, Product> implements ProductService {

    @Autowired
    private ProductMapper productMapper;

    @Override
    public boolean updateProduct(String id, String product, String manufacturer, String inventory, String state, String money) {
        try {
            Product product2 = productMapper.selectOne(new QueryWrapper<Product>().eq("id", Integer.parseInt(id)));
            if (product2 == null) {
                return false;
            }
            product2.setProduct(product);
            product2.setManufacturer(manufacturer);
            product2.setInventory(Integer.parseInt(inventory));
            product2.setState(state);
            product2.setMoney(Integer.parseInt(money));
            return productMapper.updateById(product2) != 0;
        } catch (Exception e) {
            return false;
        }
    }

    @Override
    public Boolean insert(String product, String manufacturer, String inventory, String state, String money) {
        try {
            Product product1 = new Product();
            product1.setProduct(product);
            product1.setManufacturer(manufacturer);
            product1.setInventory(Integer.parseInt(inventory));
            product1.setState(state);
            product1.setMoney(Integer.parseInt(money));
            return productMapper.insert(product1) != 0;
        } catch (Exception e) {
            return false;
        }
    }

}
